package com.xhs.controller;

import com.xhs.message.Result;
import com.xhs.message.ReturnResult;
import com.xhs.service.impl.CacheRedisServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @desc: 装饰模式
 * @projectName: tools-parent
 * @author: xhs
 * @date: 2022/12/4 23:27
 * @version: JDK 1.8
 */
@RestController
@RequestMapping("/decorate")
public class DecorateController {

    /**
     * 这边注入最后一级缓存
     */
    @Autowired
    private CacheRedisServiceImpl redisService;

    /**
     * 从缓存中查询数据
     *
     * @param key
     * @return
     */
    @PostMapping("/getCachData")
    public ReturnResult<Object> getCachData(String key) {
        String cache = redisService.getCache(key);
        return ReturnResult.build(Result.SUCCESS).setData(cache);
    }
}
